package ch.nostromo.tiffanys.engines.tiffanys.board.pieces;
import ch.nostromo.tiffanys.engines.tiffanys.board.TiffanysMove;
import ch.nostromo.tiffanys.game.board.Board;

public class TiffanysKnight  extends TiffanysPiece {


  private static final int myPieceCode = Board.PIECE_KNIGHT;
  public static final int MATERIAL_VALUE = 300;

  public static int getMoveList(int currentPosition, int oldArrayLength, TiffanysMove[] moves, int[] enemyValues, boolean[] validMoveFields) {
    int arrayLength = oldArrayLength;

    int toField = currentPosition + 19;
    if (validMoveFields[toField]) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      }
      arrayLength ++;
    }

    toField = currentPosition + 21;
    if (validMoveFields[toField]) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      }
      arrayLength ++;
    }

    toField = currentPosition + 12;
    if (validMoveFields[toField]) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      }
      arrayLength ++;
    }

    toField = currentPosition -8;
    if (validMoveFields[toField]) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      }
      arrayLength ++;
    }

    toField = currentPosition -19;
    if (validMoveFields[toField]) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      }
      arrayLength ++;
    }

    toField = currentPosition -21;
    if (validMoveFields[toField]) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      }
      arrayLength ++;
    }

    toField = currentPosition -12;
    if (validMoveFields[toField]) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      }
      arrayLength ++;
    }

    toField = currentPosition +8;
    if (validMoveFields[toField]) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      }
      arrayLength ++;
    }


    return arrayLength;

  }

  public static int getHitMoveList(int currentPosition, int oldArrayLength, TiffanysMove[] moves, int[] enemyValues) {
    int arrayLength = oldArrayLength;

    int toField = currentPosition + 19;
    if (enemyValues[toField] !=0) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength ++;
    }

    toField = currentPosition + 21;
    if (enemyValues[toField] !=0) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength ++;
    }

    toField = currentPosition + 12;
    if (enemyValues[toField] !=0) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength ++;
    }

    toField = currentPosition -8;
    if (enemyValues[toField] !=0) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength ++;
    }

    toField = currentPosition -19;
    if (enemyValues[toField] !=0) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength ++;
    }

    toField = currentPosition -21;
    if (enemyValues[toField] !=0) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength ++;
    }

    toField = currentPosition -12;
    if (enemyValues[toField] !=0) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength ++;
    }

    toField = currentPosition +8;
    if (enemyValues[toField] !=0) {
      moves[arrayLength].setMove(currentPosition, toField, myPieceCode);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength ++;
    }

    return arrayLength;

  }
/*
  public static int[] getTestBoard() {
    int[] board = new int[120];
    Board.clearBoard(board);

    board[64] += Board.OWNER_WHITE + Board.PIECE_KNIGHT;
    board[83] += Board.OWNER_WHITE + Board.PIECE_BISHOP;

    Board.setEmptyFields(board);

    return board;
  }
*/
}